# a function that performs the Lilliefors test for normality element-wise to all matrices in a structure array
# version: Sep 2020
# ENSURE that Octave can find the function, use the "addpath" command: addpath ("/[insert the path to your Octave folder]/Octave")

# function arguments:
# name - a structure array where the matrices are stored
# each element in a matrix is indexed by i (row) and j (column), and k is the field number in the structure array
# this function first reshapes all K i-jth elements into a vector (=sample) and then runs the test looping through all I x J vectors
function L = struct_Ltest (name)
# get the number of fields in the structure
nfs = numfields (name);
# transform the structure into a 3-dimensional tensor
k = 1;
for [val, key] = name
	T(:, :, k++) = val;
endfor
# rotate the initial tensor switching its third and second dimensions
T = flip(rotdim(T, -1, [2,3]),3);
# get the size of matrices within the structure array, handling the first field
[nr, nc] = size(name.(cell2mat(fieldnames(name)(1))));
# set an initial matrix to hold the results
L = zeros(nr,nc);
# perform the Lilliefors test to each i-jth vector
for i = 1:nr
	for j = 1:nc
		L(i,j) = Ltest2(T(i,:,j));
	endfor
endfor
endfunction
